package org.baicaixiaozhan.learn.guava.base;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import java.util.*;
import java.util.stream.Collectors;

/**
 * DESC: {@link Joiner} 示例
 *
 * @author : baicaixiaozhan
 * @since : 2020-11-12
 */
public class StringJoiningDemo {

    public static void main(String[] args) {

        List<String> dataList = Lists.newArrayList("one", "two", "three", null, "fives");

        // Guava
        // 跳过 null 字符串
        String str = Joiner.on(", ").skipNulls().join(dataList);
        System.out.println(str);

        // JDK 1.8
        String str2 = String.join(", ", dataList);
        System.out.println(str2);

        String str3 = dataList.stream().collect(Collectors.joining(", "));
        System.out.println(str3);
    }
}
